/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package game.platformer.levels;
import game.platformer.Player;
import game.platformer.interfaces.MapScreen;
import game.platformer.platformer;
import org.anddev.andengine.engine.handler.IUpdateHandler;
import org.anddev.andengine.entity.scene.background.SpriteBackground;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.extension.physics.box2d.PhysicsWorld;
/**
 *
 * @author cow
 */
public final class levelTwo implements Level {
	//varblock-------------------------
	private platformer game;
	private boolean loaded;  //is the level on screen?
	private int height, width;
	private levelDeathBox boundry;
	levelExit forwardExit;
	levelExit backwardExit;
	//platforms------------------------
	levelPlatform[] platforms;
	//---------------------------------
	//constructor================================
	public levelTwo(platformer game){
		//save paramiters
		this.game = game;

		//initialize data
		height = 1000;
		width = 2000;
		loaded = false;
	}
	//load up the textures=======================
	public void loadTextures(){
	}
	//level loading textures=====================
	public boolean isLoaded(){
		return loaded;
	}
	public void loadLevel(int entranceX, int entreanceY){
		//references-------------------
		industryTextureSet texset = platformer.getLevelManager().getIndustryTexSet();
		MapScreen scr = platformer.getScreenManager().getMapScreen();

		//set background---------------
		Sprite temp = new Sprite(0, 0, texset.getBackground());
		scr.setBackground(new SpriteBackground(temp));

		//place the deathBox-----------
		boundry = new levelDeathBox(width, height);
		boundry.setLastEntryPoint(entranceX, entreanceY);
		boundry.place();

		//setup platforms--------------
		platforms = new levelPlatform[]{
				new levelPlatform(texset.getIndustBaseWide(), texset.getJunkDecorWide(), 100, 300),
				new levelPlatform(texset.getIndustBaseHalf(), 400, 300),
				new levelPlatform(texset.getIndustBaseHalf(), 150, 400),
				new levelPlatform(texset.getIndustBaseHalf(), texset.getJunkDecorHalf(), 750, 400)
			};

		//place platforms--------------,
		for (levelPlatform p : platforms) {
			p.place();
		}

		//place the player-------------
		Player.getPlayer().place(entranceX, entreanceY);


		// load exits
		forwardExit = new levelExit(800, 350, 100, 100, 2);//exit location, next level entrance location, levelID
		backwardExit = new levelExit(350, 400, 100, 100, 0);
		forwardExit.place();
		backwardExit.place();

	}
	public void unloadLevel(){
		//references-------------------
		final MapScreen scr = platformer.getScreenManager().getMapScreen();
		final PhysicsWorld pw = platformer.getPhysicsWorld();
		final IUpdateHandler remover;
		//-----------------------------

		for(levelPlatform p : platforms){
			scr.removePlatform(p);
		}
		scr.removeEntity(forwardExit);
		scr.removeEntity(backwardExit);
		scr.removeEntity(boundry);

		loaded = false;
	}
	//accessors==================================
	public int getWidth(){
		return width;
	}
	public int getHeight(){
		return height;
	}
	public int getNumExits(){
		return 0;
	}
	//returns if the param collides with the platforms
	public boolean colidesWithPlatform(Sprite colideable){
		for (levelPlatform p : platforms) {
			if(p.getSpriteRep().collidesWith(colideable)){
				return true;
			}
		}
		return false;
	}
}
